<?php
/**
 * Author Yulin
 * Func   首页上获取彩种信息数据
 */
defined('IN_YuLin') || exit('NO PERMIT!');
$res          = array();
// 获取江苏快3当前最新的开奖期号以及开奖信息
$js_k3_Sql  = 'SELECT k3.* FROM ' . Table('lottery_k3') . ' AS k3
                LEFT JOIN ' . Table('lottery') . ' AS lott
                ON k3.`tid` = lott.`id`
                WHERE lott.`sname` = "jsk3" AND k3.`code` != "" ORDER BY id DESC LIMIT 1';
$k3OpenInfo = $db->getrow($js_k3_Sql);
// 获取重庆时时彩的最新期号以及开奖信息
$cq_ssc_Sql = 'SELECT k3.* FROM ' . Table('lottery_k3') . ' AS k3
                LEFT JOIN ' . Table('lottery') . ' AS lott
                ON k3.`tid` = lott.`id`
                WHERE lott.`sname` = "cqssc" AND k3.`code` != "" ORDER BY id DESC LIMIT 1';
$sscOpenInfo= $db->getrow($cq_ssc_Sql);
// 获取上海11选5最新的期号以及开奖信息
$sh_syxw_Sql    = 'SELECT k3.* FROM ' . Table('lottery_k3') . ' AS k3
                LEFT JOIN ' . Table('lottery') . ' AS lott
                ON k3.`tid` = lott.`id`
                WHERE lott.`sname` = "sh11x5" AND k3.`code` != "" ORDER BY id DESC LIMIT 1';
$cqsscOpenInfo  = $db->getrow($sh_syxw_Sql);
// 载入页面左侧彩种信息
// $navSql = "SELECT a.id, a.ptid,a.ename,a.title,a.per_explain,b.tags FROM yulin_lottery as a LEFT JOIN yulin_lottery_category as b on a.cate_id = b.id WHERE a.id in (SELECT hid FROM yulin_lottery_curr)";
$navSql         = "SELECT a.`id`,a.`ptid`,a.`title`,a.`per_explain`,b.`tags` FROM ".Table('lottery')." AS a 
                LEFT JOIN ".Table('lottery_category')." AS b 
                ON a.`cate_id` = b.`id` 
                WHERE a.recommend = 1 ORDER BY listorder asc LIMIT 10";
$lottMenuList = $db->getall($navSql);


// 载入中奖信息
$zuixin_zj_sql = 'SELECT main.`uid`, main.`order_no`,
                	u.`username`, u.head_pic,
                	item.`cn_play`, item.`money_unit`, item.`num`, item.`odds`
                FROM ' . Table('lottery_order_item') . ' AS item
                LEFT JOIN ' . Table('lottery_order_main') . ' AS main
                ON item.`o_id` = main.`id`
                LEFT JOIN ' . Table('user') . ' AS u
                ON main.`uid` = u.`id`
                WHERE item.`winner` = 2 AND item.`odds` > 0 ORDER BY item.`id` DESC LIMIT 30';
$zj_data      = $db->getall($zuixin_zj_sql);
// 累计中奖金额排名
$zj_sum_sort  = 'SELECT SUM(item.`prize`) as winAmount, main.`uid`, main.`order_no`,
                	u.`username`, u.head_pic,
                	item.`cn_play`, item.`money_unit`, item.`num`, item.`odds`
                FROM ' . Table('lottery_order_item') . ' AS item
                LEFT JOIN ' . Table('lottery_order_main') . ' AS main
                ON item.`o_id` = main.`id`
                LEFT JOIN ' . Table('user') . ' AS u
                ON main.`uid` = u.`id`
                WHERE item.`winner` = 2 AND main.`createtime` < ' . strtotime(date('Y-m-d')) . ' AND item.`prize` > 0
                GROUP BY main.`uid` ORDER BY winAmount DESC LIMIT 3';
// main.`createtime` > ' . strtotime('-1 day') . ' AND    昨日盈利，这里把开始时间先去掉

$zj_sum_data = $db->getall($zj_sum_sort);

$res['openLott']['js_k3']   = $k3OpenInfo;
$res['openLott']['cq_ssc']  = $sscOpenInfo;
$res['openLott']['sh_syxw'] = $cqsscOpenInfo;
$res['menuList']            = $lottMenuList;
$res['zhongjiang']          = $zj_data;
$res['zj_sum_sort']         = $zj_sum_data;

echo json_encode($res);


